package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayMqConfig;
import com.atguigu.gmall.rabbit.service.RabbitService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/mq")
public class MqSendController {

    @Resource
    private RabbitService rabbitService;

    //发消息
    @GetMapping("sendMessage")
    public Result sendMessage(String message){
        //rabbitTemplate进行转换并发送
        rabbitService.sendMessage("exchange1","routingKey11",message);
        return Result.ok();
    }

    @GetMapping("sendMessage2")
    public Result sendMessage2(String message){
        //rabbitTemplate进行转换并发送
        rabbitService.sendMessage("exchange2","routingKey2",message);
        return Result.ok();
    }

    //发送死信
    @GetMapping("/sendDeadMessage")
    public Result sendDeadMessage(String message){
        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,DeadLetterMqConfig.routing_dead_2,message,11);
        return Result.ok();
    }

    //发送插件延迟
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(DelayMqConfig.exchange_delay,DelayMqConfig.routing_delay,message,11);
        return Result.ok();
    }

}
